(function (factory) {

    // CommonJS/NodeJS
    if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
        factory(require, exports, module);
    }
    // CMD/SeaJS
    else if (typeof define === 'function') {
        define(factory);
    }
    // No module loader
    else {
        window['Loading'] = factory(function() {});
    }

}(function (require, exports, module) {

    var gifBase64 = 'url() no-repeat center center';

    var defaults = {
        zIndex: 100000,
        parentOpacity: 0,
        childOpacity: 0.8
    };

    var parent;
    var child;



    function create(options) {
    //    options = extend(defaults, options || {});
        parent = document.createElement('div');
        css(parent, getParentStyle(options));

        child = document.createElement('div');
        css(child, getChildStyle(options));

        parent.appendChild(child);
        document.body.appendChild(parent);
    }

    function css(obj, styles) {
        for(var key in styles) {
            obj.style[key] = styles[key];
        }
    }


    function getParentStyle(options) {
        options = options || {};
        return {
            'position': 'fixed',
            'left': 0,
            'top': 0,
            'width': '100%',
            'height': '100%',
            'background': 'rgba(0,0,0,' + (defaults.parentOpacity || options.parentOpacity)  + ')',
            'z-index': defaults.zIndex || options.zIndex
        };
    }

    function getChildStyle(options) {
        options = options || {};
        return {
            'position': 'fixed',
            'left': '50%',
            'top': '50%',
            'margin': '-30px 0 0 -30px',
            'width': '60px',
            'height': '60px',
            'border-radius': '5px',
            'background': 'rgba(0,0,0,' + (defaults.childOpacity || options.childOpacity) + ') ' + gifBase64,
            'background-size':'50% 50%',
            'z-index': (defaults.zIndex || options.zIndex) + 1
        };
    }

/*    function extend(a, b) {
        var o = {};
        for(var key in a) {
            o[key] = a[key];
        }
        for(var key in b) {
            o[key] = b[key];
        }
        return o;
    }*/

    function show(options) {
        if(document.body) {
            hide();
            create(options);
        }
    }

    function hide() {
        if(parent) {
            document.body.removeChild(parent);
            parent = null;
        }
    }

    return {
        show: show,
        hide: hide
    };

}));